#include "item.h"
#include "actor.h"
#include "queue.h"
#include "buffer.h"
#include "level.h"

extern Level Map;
extern Queue Q;
extern Actor Player;
extern Buffer Buff;

void Item::Define(int id_,string name_,char symbol_,int color_,EffectType effect_,int rarity_,int r,int c){
	id=id_;
	name=name_;
	the_name="the " + name;
	char* sub = (char *)name.c_str();
	switch(sub[0]){
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
		case 'A':
		case 'E':
		case 'I':
		case 'O':
		case 'U':
			a_name = "an " + name;
			break;
		default:
			a_name = "a " + name;
			break;
	}
	symbol=symbol_;
	color=color_;
	effect=effect_;
	rarity=rarity_;
	row=r;
	col=c;
}
void Item::CloneSelf(int r,int c,bool give_actor){
	Item* temp = new Item(*this);
	temp->SetPos(r,c);
	temp->percent_remaining=100; //didn't realize this wasn't automatic
	if(give_actor && Map.ActorPtr(r,c)!=NULL){
		Map.ActorPtr(r,c)->GetItem(temp);
	}
	else{
		Map.TilePtr(r,c)->GetItem(temp);
	}
}
void Item::SetPos(int r,int c){
	row=r;
	col=c;
}
string Item::AName(){
	string result = a_name;
	int symbol = result.find('~');
	if(symbol!=string::npos){
		result = result.substr(0,symbol) + result.substr(symbol+1,100);
	}
	if(percent_remaining < 100){
		result = IntToString(percent_remaining) + "%% of " + result;
	}
	if(id==30){ result = "the Moonscythe"; }
	return result;
}
string Item::TheName(){
	string result;
	int symbol;
	result = the_name;
	symbol = result.find('~');
	if(symbol!=string::npos){
		result = result.substr(0,symbol) + result.substr(symbol+1,100);
	}
	if(percent_remaining < 100){
		result = IntToString(percent_remaining) + "%% of " + result;
	}
	if(id==30){ result = "the Moonscythe"; }
	return result;
}
string Item::ShortDesc(){
	string result = "(an item)";
//	switch(effect){
//	}
	//or
//	switch(id){
//	}
	return result;
}

